<?php

	// TITLE: Office Accounts Model
	// FILE: app/office/model/account.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/02/11 05:54:49
	// DESCRIPTION: 
	// REQUIREMENTS: 


	$createAccount = function($id, $username, $password, $date, $status, $isAdmin, $isOffice, $personId) {
		global $con;
		$sql = 'INSERT INTO account (id, username, password, date, status, is_admin, is_office, person_id) VALUES (' . $id . ', ' . $username . ', ' . $password . ', ' . $date . ', ' . $status . ', ' . $isAdmin . ', ' . $isOffice . ', ' . $personId . ')';
		$this->open();
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		$this->close();
		return $id;
	};// end function

	$readAccount = function($id) {
		global $con;
		$sql = 'SELECT * FROM account WHERE id = ' . $id;
		$this->open();
		$results = mysqli_query($con, $sql);
		$this->close();
		if ($results) {
			$result = mysqli_fetch_array($results);
			$account = new Account();
			$account->setId($result[0]);
			$account->setUsername($result[1]);
			$account->setPassword($result[2]);
			$account->setDate($result[3]);
			$account->setStatus($result[4]);
			$account->setIsAdmin($result[5]);
			$account->setIsOffice($result[6]);
			$account->setPersonId($this->readPerson($result[7]));
		} else {
			$account = false;
		}
		return $account;
	};// end function

	$updateAccount = function($id, $username, $password, $date, $status, $isAdmin, $isOffice, $personId) {
		global $con;
		$sql = 'UPDATE account SET username = ' . $username . ', password = ' . $password . ', date = ' . $date . ', status = ' . $status . ', is_admin = ' . $isAdmin . ', is_office = ' . $isOffice . ', person_id = ' . $personId . ' WHERE id = ' . $id;
		$this->open();
		$result = mysqli_query($con, $sql);
		$this->close();
		return $result;
	};// end function

	$deleteAccount = function($id) {
		global $con;
		$sql = 'DELETE FROM account WHERE id = ' . $id;
		$this->open();
		$result = mysqli_query($con, $sql);
		$this->close();
		return $result;
	};// end function

	$listAccount = function() {
		global $con;
		$sql = 'SELECT * FROM account';
		$this->open();
		$results = mysqli_query($con, $sql);
		$this->close();
		if ($results) {
			$accounts = array();
			while ($result = mysqli_fetch_array($results)) {
				$account = new Account();
				$account->setId($result[0]);
				$account->setUsername($result[1]);
				$account->setPassword($result[2]);
				$account->setDate($result[3]);
				$account->setStatus($result[4]);
				$account->setIsAdmin($result[5]);
				$account->setIsOffice($result[6]);
				$account->setPersonId($this->readPerson($result[7]));
				$accounts[] = $account;
			}// end while
		} else {
			$accounts = false;
		}
		return $accounts;
	};// end function

	// account_recovery // --------------------

	$createAccountRecovery = function($accountId, $temporaryPassword, $date, $statusId) {
		global $con;
		$sql = 'INSERT INTO account_recovery (account_id, temporary_password, date, status_id) VALUES (' . $accountId . ', ' . $temporaryPassword . ', ' . $date . ', ' . $statusId . ')';
		$this->open();
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		$this->close();
		return $id;
	};// end function

	$readAccountRecovery = function($id) {
		global $con;
		$sql = 'SELECT * FROM account_recovery WHERE id = ' . $id;
		$this->open();
		$results = mysqli_query($con, $sql);
		$this->close();
		if ($results) {
			$result = mysqli_fetch_array($results);
			$accountRecovery = new AccountRecovery();
			$accountRecovery->setAccountId($this->readAccount($result[0]));
			$accountRecovery->setTemporaryPassword($result[1]);
			$accountRecovery->setDate($result[2]);
			$accountRecovery->setStatusId($this->readStatus($result[3]));
		} else {
			$accountRecovery = false;
		}
		return $accountRecovery;
	};// end function

	$updateAccountRecovery = function($accountId, $temporaryPassword, $date, $statusId) {
		global $con;
		$sql = 'UPDATE account_recovery SET account_id = ' . $account_id . ', temporary_password = ' . $temporaryPassword . ', date = ' . $date . ', status_id = ' . $statusId . ' WHERE id = ' . $id;
		$this->open();
		$result = mysqli_query($con, $sql);
		$this->close();
		return $result;
	};// end function

	$deleteAccountRecovery = function($id) {
		global $con;
		$sql = 'DELETE FROM account_recovery WHERE account_id = ' . $id;
		$this->open();
		$result = mysqli_query($con, $sql);
		$this->close();
		return $result;
	};// end function

	$listAccountRecovery = function() {
		global $con;
		$sql = 'SELECT * FROM account_recovery';
		$this->open();
		$results = mysqli_query($con, $sql);
		$this->close();
		if ($results) {
			$accountRecoverys = array();
			while ($result = mysqli_fetch_array($results)) {
				$accountRecovery = new AccountRecovery();
				$accountRecovery->setAccountId($this->readAccount($result[0]));
				$accountRecovery->setTemporaryPassword($result[1]);
				$accountRecovery->setDate($result[2]);
				$accountRecovery->setStatusId($this->readStatus($result[3]));
				$accountRecoverys[] = $accountRecovery;
			}// end while
		} else {
			$accountRecoverys = false;
		}
		return $accountRecoverys;
	};// end function

	// account_recovery_log // --------------------

	$createAccountRecoveryLog = function($accountId, $date) {
		global $con;
		$sql = 'INSERT INTO account_recovery_log (account_id, date) VALUES (' . $accountId . ', ' . $date . ')';
		$this->open();
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		$this->close();
		return $id;
	};// end function

	$readAccountRecoveryLog = function($id) {
		global $con;
		$sql = 'SELECT * FROM account_recovery_log WHERE id = ' . $id;
		$this->open();
		$results = mysqli_query($con, $sql);
		$this->close();
		if ($results) {
			$result = mysqli_fetch_array($results);
			$accountRecoveryLog = new AccountRecoveryLog();
			$accountRecoveryLog->setAccountId($this->readAccount($result[0]));
			$accountRecoveryLog->setDate($result[1]);
		} else {
			$accountRecoveryLog = false;
		}
		return $accountRecoveryLog;
	};// end function

	$updateAccountRecoveryLog = function($accountId, $date) {
		global $con;
		$sql = 'UPDATE account_recovery_log SET account_id = ' . $account_id . ', date = ' . $date . ' WHERE id = ' . $id;
		$this->open();
		$result = mysqli_query($con, $sql);
		$this->close();
		return $result;
	};// end function

	$deleteAccountRecoveryLog = function($id) {
		global $con;
		$sql = 'DELETE FROM account_recovery_log WHERE account_id = ' . $id;
		$this->open();
		$result = mysqli_query($con, $sql);
		$this->close();
		return $result;
	};// end function

	$listAccountRecoveryLog = function() {
		global $con;
		$sql = 'SELECT * FROM account_recovery_log';
		$this->open();
		$results = mysqli_query($con, $sql);
		$this->close();
		if ($results) {
			$accountRecoveryLogs = array();
			while ($result = mysqli_fetch_array($results)) {
				$accountRecoveryLog = new AccountRecoveryLog();
				$accountRecoveryLog->setAccountId($this->readAccount($result[0]));
				$accountRecoveryLog->setDate($result[1]);
				$accountRecoveryLogs[] = $accountRecoveryLog;
			}// end while
		} else {
			$accountRecoveryLogs = false;
		}
		return $accountRecoveryLogs;
	};// end function

	// account_recovery_status // --------------------

	$createAccountRecoveryStatus = function($id, $title, $description) {
		global $con;
		$sql = 'INSERT INTO account_recovery_status (id, title, description) VALUES (' . $id . ', ' . $title . ', ' . $description . ')';
		$this->open();
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		$this->close();
		return $id;
	};// end function

	$readAccountRecoveryStatus = function($id) {
		global $con;
		$sql = 'SELECT * FROM account_recovery_status WHERE id = ' . $id;
		$this->open();
		$results = mysqli_query($con, $sql);
		$this->close();
		if ($results) {
			$result = mysqli_fetch_array($results);
			$accountRecoveryStatus = new AccountRecoveryStatus();
			$accountRecoveryStatus->setId($result[0]);
			$accountRecoveryStatus->setTitle($result[1]);
			$accountRecoveryStatus->setDescription($result[2]);
		} else {
			$accountRecoveryStatus = false;
		}
		return $accountRecoveryStatus;
	};// end function

	$updateAccountRecoveryStatus = function($id, $title, $description) {
		global $con;
		$sql = 'UPDATE account_recovery_status SET title = ' . $title . ', description = ' . $description . ' WHERE id = ' . $id;
		$this->open();
		$result = mysqli_query($con, $sql);
		$this->close();
		return $result;
	};// end function

	$deleteAccountRecoveryStatus = function($id) {
		global $con;
		$sql = 'DELETE FROM account_recovery_status WHERE id = ' . $id;
		$this->open();
		$result = mysqli_query($con, $sql);
		$this->close();
		return $result;
	};// end function

	$listAccountRecoveryStatus = function() {
		global $con;
		$sql = 'SELECT * FROM account_recovery_status';
		$this->open();
		$results = mysqli_query($con, $sql);
		$this->close();
		if ($results) {
			$accountRecoveryStatuss = array();
			while ($result = mysqli_fetch_array($results)) {
				$accountRecoveryStatus = new AccountRecoveryStatus();
				$accountRecoveryStatus->setId($result[0]);
				$accountRecoveryStatus->setTitle($result[1]);
				$accountRecoveryStatus->setDescription($result[2]);
				$accountRecoveryStatuss[] = $accountRecoveryStatus;
			}// end while
		} else {
			$accountRecoveryStatuss = false;
		}
		return $accountRecoveryStatuss;
	};// end function

	// account_status // --------------------

	$createAccountStatus = function($accountId, $statusId, $adminWhoEntered, $admintWhenEntered) {
		global $con;
		$sql = 'INSERT INTO account_status (account_id, status_id, admin_who_entered, admint_when_entered) VALUES (' . $accountId . ', ' . $statusId . ', ' . $adminWhoEntered . ', ' . $admintWhenEntered . ')';
		$this->open();
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		$this->close();
		return $id;
	};// end function

	$readAccountStatus = function($id) {
		global $con;
		$sql = 'SELECT * FROM account_status WHERE id = ' . $id;
		$this->open();
		$results = mysqli_query($con, $sql);
		$this->close();
		if ($results) {
			$result = mysqli_fetch_array($results);
			$accountStatus = new AccountStatus();
			$accountStatus->setAccountId($this->readAccount($result[0]));
			$accountStatus->setStatusId($this->readStatus($result[1]));
			$accountStatus->setAdminWhoEntered($result[2]);
			$accountStatus->setAdmintWhenEntered($result[3]);
		} else {
			$accountStatus = false;
		}
		return $accountStatus;
	};// end function

	$updateAccountStatus = function($accountId, $statusId, $adminWhoEntered, $admintWhenEntered) {
		global $con;
		$sql = 'UPDATE account_status SET account_id = ' . $account_id . ', status_id = ' . $statusId . ', admin_who_entered = ' . $adminWhoEntered . ', admint_when_entered = ' . $admintWhenEntered . ' WHERE id = ' . $id;
		$this->open();
		$result = mysqli_query($con, $sql);
		$this->close();
		return $result;
	};// end function

	$deleteAccountStatus = function($id) {
		global $con;
		$sql = 'DELETE FROM account_status WHERE account_id = ' . $id;
		$this->open();
		$result = mysqli_query($con, $sql);
		$this->close();
		return $result;
	};// end function

	$listAccountStatus = function() {
		global $con;
		$sql = 'SELECT * FROM account_status';
		$this->open();
		$results = mysqli_query($con, $sql);
		$this->close();
		if ($results) {
			$accountStatuss = array();
			while ($result = mysqli_fetch_array($results)) {
				$accountStatus = new AccountStatus();
				$accountStatus->setAccountId($this->readAccount($result[0]));
				$accountStatus->setStatusId($this->readStatus($result[1]));
				$accountStatus->setAdminWhoEntered($result[2]);
				$accountStatus->setAdmintWhenEntered($result[3]);
				$accountStatuss[] = $accountStatus;
			}// end while
		} else {
			$accountStatuss = false;
		}
		return $accountStatuss;
	};// end function

	// account_status_type // --------------------

	$createAccountStatusType = function($id, $title, $code, $description) {
		global $con;
		$sql = 'INSERT INTO account_status_type (id, title, code, description) VALUES (' . $id . ', ' . $title . ', ' . $code . ', ' . $description . ')';
		$this->open();
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		$this->close();
		return $id;
	};// end function

	$readAccountStatusType = function($id) {
		global $con;
		$sql = 'SELECT * FROM account_status_type WHERE id = ' . $id;
		$this->open();
		$results = mysqli_query($con, $sql);
		$this->close();
		if ($results) {
			$result = mysqli_fetch_array($results);
			$accountStatusType = new AccountStatusType();
			$accountStatusType->setId($result[0]);
			$accountStatusType->setTitle($result[1]);
			$accountStatusType->setCode($result[2]);
			$accountStatusType->setDescription($result[3]);
		} else {
			$accountStatusType = false;
		}
		return $accountStatusType;
	};// end function

	$updateAccountStatusType = function($id, $title, $code, $description) {
		global $con;
		$sql = 'UPDATE account_status_type SET title = ' . $title . ', code = ' . $code . ', description = ' . $description . ' WHERE id = ' . $id;
		$this->open();
		$result = mysqli_query($con, $sql);
		$this->close();
		return $result;
	};// end function

	$deleteAccountStatusType = function($id) {
		global $con;
		$sql = 'DELETE FROM account_status_type WHERE id = ' . $id;
		$this->open();
		$result = mysqli_query($con, $sql);
		$this->close();
		return $result;
	};// end function

	$listAccountStatusType = function() {
		global $con;
		$sql = 'SELECT * FROM account_status_type';
		$this->open();
		$results = mysqli_query($con, $sql);
		$this->close();
		if ($results) {
			$accountStatusTypes = array();
			while ($result = mysqli_fetch_array($results)) {
				$accountStatusType = new AccountStatusType();
				$accountStatusType->setId($result[0]);
				$accountStatusType->setTitle($result[1]);
				$accountStatusType->setCode($result[2]);
				$accountStatusType->setDescription($result[3]);
				$accountStatusTypes[] = $accountStatusType;
			}// end while
		} else {
			$accountStatusTypes = false;
		}
		return $accountStatusTypes;
	};// end function

?>
